var app = getApp(), dataApiService = require("../../provider/dataApi.js"), pipe = require("../../provider/pipe.js"), wxParseModule = require("../../wxParse/article.js");

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        isLoading: false,
        videoInfo: {},
        isVideoVisible: false,
        title: "",
        articleInfo: {}
    },
    onLoad: function(options) {
        var self = this;
        console.log(options);
        if (options.type === "notice") {
            this.setData({
                title: "通知详情"
            });
        } else if (options.type === "article") {
            this.setData({
                title: "文章详情"
            });
        }
        this.setData({
            statusBarHeight: getApp().globalData.statusBarHeight,
            titleBarHeight: getApp().globalData.titleBarHeight,
            isLoading: true
        });
        var notificationId = options.nId ? options.nId : app.globalData.id;
        dataApiService.readNotice({
            nid: notificationId
        }).then(function(apiResponse) {
            console.log(apiResponse);
            apiResponse.data.info.content = pipe.strcharacterDiscode(apiResponse.data.info.content).replace(/\<img/gi, '<img style="max-width:100px!important;height:auto"');
            wxParseModule.wxParse("article", "html", apiResponse.data.info.content, self, 15);
            if (apiResponse.data.info.video !== undefined) {
                self.setData({
                    videoInfo: apiResponse.data.info.video,
                    isVideoVisible: true
                });
            }
            self.setData({
                articleInfo: apiResponse.data.info,
                isLoading: false
            });
        }).catch(function(apiError) {
            self.setData({
                isLoading: false
            });
            console.log(apiError);
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: -1
        });
    },
    onShareAppMessage: function() {
        return {
            title: "分享文章",
            path: "/pages/article-info/article-info?type=article&nId=" + getApp().globalData.id
        };
    }
});